package com.sixkey.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.annotation.OperationLog;
import com.sixkey.entity.Room;
import com.sixkey.entity.User;
import com.sixkey.entity.vo.RoomVo;
import com.sixkey.entity.vo.UserVo;
import com.sixkey.response.Response;
import com.sixkey.service.IRoomService;
import com.sixkey.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-01
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/room")
public class RoomController {

    private final IRoomService roomService;


    /**
     * 分页获取会议室数据
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize,
                         RoomVo roomVo) {
        log.info("分页获取会议室数据请求进来");
        Page<Room> roomPage = roomService.queryList(pageNo,pageSize,roomVo);
        return Response.success(roomPage);
    }

    /**
     * 新增会议室
     * @param room
     * @return
     */
    @PostMapping("/save")
    @OperationLog("新增会议室")
    public Response save(@RequestBody @Valid Room room){
        log.info("新增会议室请求进来");
        roomService.save(room);
        return Response.success();
    }

    /**
     * 修改会议室
     * @param room
     * @return
     */
    @PutMapping("/update")
    @OperationLog("修改会议室")
    public Response update(@RequestBody @Valid Room room){
        log.info("修改会议室请求进来");
        roomService.updateById(room);
        return Response.success();
    }

    /**
     * 删除会议室
     * @param
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @OperationLog("删除会议室")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("删除会议室请求进来");
        roomService.removeBatch(id);
        return Response.success();
    }


    /**
     * 会议室数据回显
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getRoomInfo(@PathVariable("id") Integer id){
        log.info("会议室数据回显请求进来");
        Room room = roomService.getById(id);
        return Response.success(room);
    }
}
